package usaco.c2007.january.bronze;

import java.util.Scanner;

/*
 * p2767
 * USACO 2007 January - Bronze
 */

public class p2767 {

	static int A, B, D, count;
	static boolean flag;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		A = scanner.nextInt();
		B = scanner.nextInt();
		D = scanner.nextInt();
		count = 0;
		for (int i=A;i<=B;++i) {
			if (isPrime(i)) {
				int tmp = i;
				while (tmp > 0) {
					if (tmp % 10 == D) {
						++count;
						break;
					}
					tmp /= 10;
				}
			}
		}
		System.out.println(count);

	}

	private static boolean isPrime(int n) {
		if (n <= 1) return false;
		else if (n == 2 || n == 3) {
			return true;
		}
		else {
			int i = 2;
			while (i*i <= n) {
				if (n % i == 0) {
					return false;
				}
				i++;
			}
			return true;
		}
	}

}
